﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ERPStore.Services
{
	public class ArianeServiceBus : IServiceBus
	{
		private Ariane.IServiceBus m_ServiceBus;

		public ArianeServiceBus(Ariane.IServiceBus serviceBus)
		{
			m_ServiceBus = serviceBus;
		}

		#region IServiceBus Members

		public void RegisterQueuesFromConfig(string configFileName = null)
		{
			m_ServiceBus.Register.AddFromConfig(configFileName);
		}

		public void RegisterQueue(string queueName, Type typeReader, Type typeMedium = null)
		{
			var queue = new Ariane.QueueSetting()
			{
				Name = queueName,
				TypeMedium = typeMedium,
				TypeReader = typeReader,
			};
			m_ServiceBus.Register.AddQueue(queue);
		}

		public void StartReading()
		{
			if (GlobalConfiguration.Configuration.ExecutingContext == Models.ExecutingContext.Developpement)
			{
				return;
			}
			m_ServiceBus.StartReading();
		}

		public void StopReading()
		{
			m_ServiceBus.StopReading();
		}

		public void PauseReading()
		{
			m_ServiceBus.PauseReading();
		}

		public void Send<T>(string queueName, T body, string label = null)
		{
			m_ServiceBus.Send(queueName, body, label);
		}

		#endregion
	}
}
